package git.luohao.config;

import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration;
import git.luohao.filerule.FileDataSourceHandler;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(SentinelAutoConfiguration.class)
@ConfigurationProperties("spring.cloud.sentinel.datasource.flow-rules.file.file")
public class FileRuleAutoWriteConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public FileDataSourceHandler fileDataSourceHandler(SentinelProperties sentinelProperties) {
        return new FileDataSourceHandler(sentinelProperties);
    }
}
